package com.soft.javase.day02.practice.order;

import java.util.Arrays;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/16
 */
public class User {
    private String name;
    private String address;
    private String phoneNumber;
    private Order[] orders;

    public User(String name, String address, String phoneNumber) {
        this.name = name;
        this.address = address;
        this.phoneNumber = phoneNumber;
        this.orders = new Order[0]; // 初始化为空数组
    }

    // 下单方法
    public void placeOrder(long orderNumber, Goods[] goods) {
        Order newOrder = new Order(orderNumber, this, goods);
        // 扩展订单数组并添加新订单
        orders = Arrays.copyOf(orders, orders.length + 1);
        orders[orders.length - 1] = newOrder;
        System.out.println("用户 " + name + " 下单成功，订单号: " + orderNumber);
    }

    public String getName() { return name; }
    public String getAddress() { return address; }
    public String getPhoneNumber() { return phoneNumber; }
    public Order[] getOrders() { return orders; }

}
